﻿@using System.Collections
@using System.Linq
@{
    Style.Require("NineSeas.CategorySelector");
    Style.Require("FancyBox");
    Script.Require("FancyBox");
    Script.Require("NineSeas.CategorySelector");

    var categoryIds = new List<int>();
}
<div class="categorySelector">
    <div class="selected-items">
        @if (Model.SelectedCategories != null) {
        foreach(var category in Model.SelectedCategories) {
            categoryIds.Add(category.Id);
        <span class="category" data-id="@category.Id">
            @category.Name
            <a>x</a>
        </span>
        }
        }
    </div>
    <input type="hidden" id="categoryIds" name="CategoryIds" value="@String.Join(", ", categoryIds)" />
    <p style="clear: both;">
        <a href="javascript:;" class="open-button">@T("Choose a category")</a>
    </p>
    <div class="selector">
        @{var i = 0; var closed = true;}
        @foreach (var category in Model.Categories)
        {
            if (i % 11 == 0)
            {
                closed = false;
                @:<div class="group">
            } 
            <span class="category @(categoryIds.Contains(category.Id) ? "selected" : "")" data-id="@category.Id">
                @category.Name
            </span>
            if (i != 0 && i % 11 == 10) {
                closed = true;
                @:</div>              
            }
            i++;
        }
        @if (!closed)
        {
            @:</div>
        } 
    </div>
</div>